package com.library.settings.service.impl;

import com.library.settings.mapper.UserMapper;
import com.library.settings.pojo.User;
import com.library.settings.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service("userService")
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public int saveUser(User user) {
        // 保证账号唯一
        User res = userMapper.queryUserByAccount(user.getUserAccount());
        if(res!=null){
            return 0;
        }
        return userMapper.insertUser(user);
    }

    @Override
    public User queryUserByAccount(String userAccount) {
        return userMapper.queryUserByAccount(userAccount);
    }

    @Override
    public User queryUserByLoginActAndLogonPwd(Map<String, Object> map) {
        return userMapper.queryUserByLoginActAndLogonPwd(map);
    }

    @Override
    public List<User> queryUsersByActNameAndSexForPage(Map<String, Object> map) {
        return userMapper.selectUsersByActNameAndSexForPage(map);
    }

    @Override
    public int queryUserByActNameAndSexForRows(Map<String, Object> map) {
        return userMapper.selectUsersByActNameAndSexForRows(map);
    }

    @Override
    public int deleteUserByUserId(String userId) {
        return userMapper.deleteUserByUserId(userId);
    }

    @Override
    public User queryUserByUserId(String userId) {
        return userMapper.selectUserByUserId(userId);
    }

    @Override
    public int updateUser(User user) {
        return userMapper.updateUser(user);
    }
}
